#include "StdAfx.h"
#include "HuangliDao.h"

CHuangliDao::~CHuangliDao(void)
{
}

HuangliNode CHuangliDao::GetHuangliDatabyDate(const wstring &Date)
{
	HuangliNode Temp;
	if (Date.empty())
	{
		return Temp;
	}
	CppSQLite3DB db;
	try
	{
		wstring dbPath = AppInit.GetDbFileDir();
		dbPath += DB_HUANGLIDATA;
		db.open(dbPath.c_str());		
		CString strSql;
		strSql.Format(_T("select * from HL_s where sDate='%s';"), Date.c_str());
		CppSQLite3Query q = db.execQuery(strSql.GetBuffer(0));
		if (!q.eof())
		{
			Temp.Id = _wtoi(q.fieldValue(0));
			Temp.sData = q.fieldValue(1);
			Temp.nYear = q.fieldValue(2);
			Temp.nMouth = q.fieldValue(3);
			Temp.nDay = q.fieldValue(4);
			Temp.nToday = q.fieldValue(5);
			Temp.nYu = q.fieldValue(6);
			Temp.nJi = q.fieldValue(7);
			Temp.nChong = q.fieldValue(8);
			Temp.nSha = q.fieldValue(9);
			Temp.nZhengchong = q.fieldValue(11);
			Temp.nTaishen = q.fieldValue(12);
			Temp.nJq = q.fieldValue(13);
			Temp.nSolarTerm = q.fieldValue(14);
		}
		q.finalize();
	}
	catch(CppSQLite3Exception ex)
	{
		::MessageBox(NULL, (LPCWSTR)ex.errorMessage(), (LPCWSTR)"", MB_OK);
	}
	db.close();
	return Temp;
}